import { Home } from 'home-model.js';
import { My } from '../my/my-model.js';
var home = new Home(); //实例化 首页 对象
var my = new My();
Page({
  data: {
    loadingHidden: false
  },
  onLoad: function () {
    home.getUid((data) => {
      var pages = getCurrentPages()    //获取加载的页面

      var currentPage = pages[pages.length - 1]    //获取当前页面的对象

      var url = currentPage.route    //当前页面url

      var options = currentPage.options //参数
      var param = new Array()
          param['pid'] = data,
          param['uid'] = options.uid
      home.setPid(param, (data) => {
        console.log(data)
      })
      // console.log(pid);
    })
    this._loadData();
  },

  /*加载所有数据*/
  _loadData: function (callback) {


    var that = this;

    //获取Uid

    // 获得bannar信息
    home.getBannerData((data) => {
      that.setData({
        bannerArr: data,
      });
    });

    /*获取主题信息*/
    home.getThemeData((data) => {
      that.setData({
        themeArr: data,

      });
    });

    /*获取单品信息*/
    home.getProductorData((data) => {

      that.setData({
        productsArr: data,

      });
      callback && callback();
    });

    my.getUserInfo((data) => {

      that.setData({
        userInfo: data,

      });

    });
    setTimeout(function () {
      that.setData({

        loadingHidden: true
      });
    }, 2000);
    // wx.getSetting({})
  },

  /*跳转到商品详情*/
  onProductsItemTap: function (event) {
    var id = home.getDataSet(event, 'id');
    wx.navigateTo({
      url: '../product/product?id=' + id
    })
  },

  /*跳转到主题列表*/
  onThemesItemTap: function (event) {
    var id = home.getDataSet(event, 'id');
    var name = home.getDataSet(event, 'name');
    wx.navigateTo({
      url: '../theme/theme?id=' + id + '&name=' + name
    })
  },

  /*下拉刷新页面*/
  onPullDownRefresh: function () {
    this._loadData(() => {
      wx.stopPullDownRefresh()
    });
  },

  //分享效果
  onShareAppMessage: function () {
    return {
      title: '爱车易得',
      path: 'pages/home/home'
    }
  },





})
